﻿using System;

namespace CsharpHomeworl3_1
{
    class Program
    {


        public class Node<T>
        {
            public Node<T> Next { get; set; }
            public T Data { get; set; }

            public Node(T t)
            {
                Next = null;
                Data = t;
            }
        }

        public class GenericList<T>
        {
            private Node<T> tail;
            private Node<T> head;
            public GenericList()
            {
                tail = head = null;
            }

            public Node<T> Head
            {
                get => head;
            }

            public void Add(T t)
            {
                Node<T> n = new Node<T>(t);
                if (tail == null)
                {
                    head = tail = n;
                }
                else
                {
                    tail.Next = n;
                    tail = n;

                }
            }

            static public void ForEach(GenericList<T> genericList, Action<T> action)
            {


                Node<T> node = genericList.head;

                while (node != null)
                {
                    action(node.Data);
                    node = node.Next;
                }

            }
        }

        static void Main(string[] args)
        {
            GenericList<int> a = new GenericList<int>();
            a.Add(1);
            a.Add(3);
            a.Add(1);

            GenericList<int>.ForEach(a, (x) => Console.WriteLine(x));
            int sum = 0;

            GenericList<int>.ForEach(a, (x) => sum += x);
            Console.WriteLine(sum);
            int biggest = a.Head.Data;
            int smallest = a.Head.Data;
            GenericList<int>.ForEach(a, (x) => biggest = x > biggest ? x : biggest);
            GenericList<int>.ForEach(a, (x) => smallest = x < biggest ? x : smallest);
            Console.WriteLine("big" + biggest);
            Console.WriteLine("sma" + smallest);
        }


    }
}

